﻿Shader "Custom/StandardOutline"
{
    Properties
    {
		[Header(Texture Group)]
		[Space(10]
		_MainTex("Albedo",2D) = "white" {}
		[NoScaleOffset]_Specular("Specular (RGB-A)",2D) = "black"{}
		[NoScaleOffset]_Normal("Normal",2D) = "bump"{}
		[NoScaleOffset]_AO("Ambient Occlusion",2D) = "white"{}
		[Header(Outline Properties)]
		[Space(10)]

		_OutlineColor("Ontline Color",Color) = (1,0,1,1)
		_OutlineWidth("Outline Width",Range(0,6)) = 0.02
    }
    SubShader
    {
        Tags { "RenderType"="Opaque"  "Queue"="Transparent"}
        //LOD 200

		Pass//描边
		{
			ZWrite off
			CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
			struct v2f
			{
				float4 vertex:SV_POSITION;
			};

		fixed4 _OutlineColor;
		fixed _OutlineWidth;
		v2f vert(appdata_base v) {
			v2f o;
			v.vertex.xyz += v.normal * _OutlineWidth;
			o.vertex = UnityObjectToClipPos(v.vertex);
			
			return o;
		}
		fixed4 frag(v2f i) :SV_Target
		{
			return _OutlineColor; 
		}
			ENDCG

		}

	
			CGPROGRAM
			// Physically based Standard lighting model, and enable shadows on all light types
			#pragma surface surf StandardSpecular fullforwardshadows

			// Use shader model 3.0 target, to get nicer looking lighting
			#pragma target 3.0

			sampler2D _MainTex;

			struct Input
			{
				float2 uv_MainTex;
			};

			sampler2D _Specular;
			sampler2D _Normal;
			sampler2D _AO;

			// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
			// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
			// #pragma instancing_options assumeuniformscaling
			UNITY_INSTANCING_BUFFER_START(Props)
				// put more per-instance properties here
			UNITY_INSTANCING_BUFFER_END(Props)

			void surf(Input IN, inout SurfaceOutputStandardSpecular o)
			{
				// Albedo comes from a texture tinted by color
				fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
				o.Albedo = c.rgb;
				//// Metallic and smoothness come from slider variables
				//o.Metallic = _Metallic;
				//o.Smoothness = _Glossiness;
				//o.Alpha = c.a;
				fixed4 specular = tex2D(_Specular, IN.uv_MainTex);
				o.Specular = specular.rgb;
				o.Smoothness = specular.a;

				o.Normal = UnpackNormal(tex2D(_Normal, IN.uv_MainTex));
				o.Occlusion = tex2D(_AO, IN.uv_MainTex);
			}
			ENDCG
		
    }
    FallBack "Diffuse"
}
